package com.example.controller;

import com.example.common.Result;
import com.example.entity.SysEmployee;
import com.example.service.SysEmployeeService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/employee")
public class SysEmployeeController {

    @Resource
    private SysEmployeeService sysEmployeeService;

    @GetMapping("/selectAll")
    public Result selectAll(SysEmployee sysEmployee){
        List<SysEmployee> list = sysEmployeeService.selectAll(sysEmployee);
        return Result.success(list);
    }

    //分页查询
    @GetMapping("/selectPage")
    public Result selectPage(SysEmployee sysEmployee,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize){
        PageInfo<SysEmployee> pageInfo = sysEmployeeService.selectPage(sysEmployee,pageNum,pageSize);
        return Result.success(pageInfo);
    }

    @PostMapping("/insert")
    public Result add(@RequestBody SysEmployee sysEmployee){
        sysEmployeeService.add(sysEmployee);
        return Result.success();
    }

    @PutMapping("/update")
    public Result update(@RequestBody SysEmployee sysEmployee){
        sysEmployeeService.update(sysEmployee);
        return Result.success();
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        sysEmployeeService.delete(id);
        return Result.success();
    }

    @DeleteMapping("/deleteBatch")
    public Result deleteBatch(@RequestBody List<Integer>ids){
        sysEmployeeService.deleteBatch(ids);
        return Result.success();
    }

}
